package pl.softech.logger;

import java.text.MessageFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

public class MyFormatter extends Formatter {

    private Date dat = new Date();
    private final static String format = "{0,date} {0,time}";
    private MessageFormat formatter;
    private Object args[] = new Object[1];
    
    @Override
    public synchronized String format(LogRecord record) {
        StringBuffer text = new StringBuffer();
        dat.setTime(record.getMillis());
        args[0] = dat;
        
        
        if (formatter == null) {
            formatter = new MessageFormat(format);
        }
        formatter.format(args, text, null);
        text.append(" ").append(record.getLevel());
        text.append(" ").append(record.getSourceClassName());
        text.append(".").append(record.getSourceMethodName());
        text.append(" ").append(formatMessage(record)).append("\n");
        
        return text.toString();
    }

}
